#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：Employment_class 
@File    ：16_协程-greenlet^gevent版.py
@IDE     ：PyCharm 
@Author  ：XiaoDengYa
@Date    ：2021/7/6/006 16:41 
"""
# from greenlet import greenlet
# import time
#
# def dtest1():
#     while True:
#         print("---A--")
#         gr2.switch()
#         time.sleep(0.5)
#
# def dtest2():
#     while True:
#         print("---B--")
#         gr1.switch()
#         time.sleep(0.5)
# if __name__ == '__main__':
#
#     gr1 = greenlet(dtest1)
#     gr2 = greenlet(dtest2)
#
#     #切换到gr1中运行
#     gr1.switch()


import gevent


def f(n):
    for i in range(n):
        print(gevent.getcurrent(), i)
        gevent.sleep(0.5) #


g1 = gevent.spawn(f, 5)
g2 = gevent.spawn(f, 5)
g3 = gevent.spawn(f, 5)
g1.join()
g2.join()
g3.join()
